package com.example.forum.controller;

import com.example.forum.common.AppResult;
import com.example.forum.exception.ApplicationException;
import com.sun.istack.internal.NotNull;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "接口测试类")
@RestController
@RequestMapping("/test")
public class TestController {
    @ApiOperation("测试接口1")
    @GetMapping("/hello")
    public String hello(){
        return "hello ,spring Boot";
    }

    @ApiOperation("测试接口2")
    @GetMapping("/application")
    public String testApplicationException(){
        throw new ApplicationException("这是一个自定义的Application");
    }

    @ApiOperation("测试接口3")
    @GetMapping("/exception")
    public String testException() throws Exception {
        throw new Exception("这是一个Exception");
    }

    @ApiOperation("测试接口4")
    @GetMapping("/helloByName")
    public AppResult helloByName(@ApiParam("姓名") @RequestParam("name") @NotNull String name){
        return AppResult.success("hello:"+name);
    }

}
